<?php
/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/
jimport( 'joomla.application.component.view' );



class JAJobBoardViewJAConfiguration extends JAView
{
    /**
     * Display the view
     */
    function display($tmpl = null)
    {
    	global $option, $_PAYMENT_OBJECTS,$jbconfig;
		$tab = JRequest::getVar('tab', 'general');
		
        $item = &$this->get('Items'); 
		
		$data = $item->data;
		$params = new JParameter($data);
		$paysys = null;
		$themes = null;
		
		require_once ("components/$option/models/jacodes.php");
		$model_codes = new JAJobBoardModelJACodes ( );
		JRequest::setVar ( 'field_id', 'ja_jobs_apply_type');
		$apply_option =  $model_codes->getItems ();
		for ($i=0;$i<count($apply_option);$i++)
			$apply_option[$i]->text = JText::_($apply_option[$i]->text);
		$temp = $params->get('apply_option');
		if (isset($temp))
			$apply_option_selected = explode(',',$params->get('apply_option'));
		else 
		$apply_option_selected = array();
		$obj_apply_option = JHTML::_('select.genericlist',   $apply_option, 'apply_option[]', 'size="5" multiple class="inputbox" style="width:150px;"', 'value', 'text', $apply_option_selected);
		
    	if($tab=='payment'){		
			$pays = get_payment_gateways();	
			$paysys = JHTML::_('select.genericlist',   $pays, 'payment[ja_default_pay_meth]', 'class="inputbox" size="1"', 'id', 'alias', $params->get('ja_default_pay_meth'));
		}
		elseif ($tab=='feeds')
		{
			$lists = array();
		
			$rssType[] = JHTML::_('select.option', '0.91','RSS 0.91');
			$rssType[] = JHTML::_('select.option', '1.0','RSS 1.0');
			$rssType[] = JHTML::_('select.option', '2.0','RSS 2.0');
			$lists['rssTypeList'] = JHTML::_('select.genericlist', $rssType, 'feeds[defaultType]', 'class="inputbox"', 'value', 'text', $params->get('defaultType'), 'defaultType');
			
			$orderings[] = JHTML::_('select.option', 'date','Date Ascending');
			$orderings[] = JHTML::_('select.option', 'rdate','Date Descending');
			$lists['orderingList'] = JHTML::_('select.genericlist', $orderings, 'feeds[orderby]', 'class="inputbox"', 'value', 'text', $params->get('orderby'), 'orderby');
			
			$numWords[] = JHTML::_('select.option','0','All');
			for ($i=25;$i<=250;$i+=25) {
				$numWords[] = JHTML::_('select.option',$i,$i);
			}
			$lists['numWordsList'] = JHTML::_('select.genericList', $numWords, 'feeds[numWords]', 'class="inputbox"','value', 'text', $params->get('numWords'),  'numWords');
			
			$authorformats[] = JHTML::_( 'select.option', 'NAME','Name Only');
			$authorformats[] = JHTML::_( 'select.option', 'EMAIL','Email Only');
			$authorformats[] = JHTML::_( 'select.option', 'NAME-EMAIL','Name and Email');
			$lists['renderAuthorList'] = JHTML::_('select.genericList', $authorformats, 'feeds[renderAuthorFormat]', 'class="inputbox"','value', 'text',$params->get('renderAuthorFormat') );
			
			$renderHTML[] = JHTML::_( 'select.option', '1','Yes');
			$renderHTML[] = JHTML::_( 'select.option', '0','No');
			$lists['renderHTMLList'] =JHTML::_( 'select.genericList',$renderHTML, 'feeds[renderHTML]', 'class="inputbox"','value', 'text',$params->get('renderHTML') );
			
			$this->assignRef('msg', $params->get('msg'));
			$this->assignRef('defaultType', $lists['rssTypeList']);
			$this->assignRef('count', $params->get('count'));
			$this->assignRef('orderby', $lists['orderingList']);
			$this->assignRef('numWords', $lists['numWordsList']);
			$this->assignRef('renderAuthorFormat', $lists['renderAuthorList']);
			$this->assignRef('renderHTML', $lists['renderHTMLList']);
			$this->assignRef('FPItemsOnly', $lists['FPItemsOnlyList']);
			$this->assignRef('cache', $params->get('cache'));
			$this->assignRef('imgUrl', $params->get('imgUrl'));
			$this->assignRef('description', $params->get('description'));
		}
		elseif($tab=='general'){
			jimport('joomla.filesystem.file');
			jimport('joomla.filesystem.folder');
			
			$theme = $jbconfig['general']->get('theme', 'default');			
			$path_themes = JPATH_SITE.DS.'components'.DS.'com_jajobboard'.DS.'views'.DS.'jajobs'.DS.'tmpl'.DS.'themes';
			if(JFolder::exists($path_themes)){	
				$folders = JFolder::folders($path_themes);
				$arr_folder = array();				
				if($folders){					
					foreach ($folders as $folder){
						if(JFile::exists($path_themes.DS.$folder.DS.'jalist-item.php')){
							$temp = new stdClass();
							$temp->value = $folder;
							$temp->text = $folder;
							$arr_folder[] = $temp;
						}						
					}					
				}
				
				if($arr_folder){
					$themes =JHTML::_( 'select.genericList', $arr_folder, 'general[theme]', 'class="inputbox"','value', 'text', $theme );
					$this->assignRef('themes', $themes);
				}
								
			}
		}
		
		$this->assignRef('tab', $tab);		
		$this->assignRef('params', $params);
		$this->assignRef('cid', $item->id);
		$this->assignRef('paysys', $paysys);
		$this->assignRef('obj_apply_option', $obj_apply_option);
		
		$this->setLayout($tab);
		
		parent::display($tmpl);
  	}  
  	
  	function getFields($table, $controlName, $select){
		$db =& JFactory::getDBO();
		
		$query = 'SELECT f.id, f.label, f.field_name '
		. ' FROM #__ja_form_fields AS f '
		. " WHERE f.published=1 and f.table_name = '".$table."' and display != 'hide_all' ORDER BY f.field_ordering ASC, f.field_name ASC"
		;
		$db->setQuery( $query );		
		$options = $db->loadObjectList();
		
		$course = array();
		$course[] = JHTML::_('select.option', "", JText::_("Not show"));
				
	    foreach ( $options as $rows ){
            $course[] = JHTML::_('select.option', $rows->field_name, JText::_("Show by: ".$rows->label) );
	    }
	    
	    $options = JHTML::_('select.genericlist', $course, $controlName, 'class="inputbox" ', 'value', 'text', $select);
		
	    return $options;
	}
  	
	function getTaxTabs(){
		global $option;
  		$type = JRequest::getVar('tab','global');
  		$tabs = '<div class="submenu-box">
						<div class="submenu-pad">
							<ul id="submenu" class="configuration">';
  		
  		$tabs.= '<li><a href="index.php?option='.$option.'&view=jaconfiguration&tab=tax"';
		if ($type == 'tax') {
			$tabs .= ' class="active" ';
		}
		$tabs.=	'>';
		$tabs.=	JText::_( 'Global TAX Setting' ).'</a></li>';
		
		$tabs.= '<li><a href="index.php?option='.$option.'&view=jatax&tab=region"';
		if ($type == 'region') {
			$tabs .= ' class="active" ';
		}
		$tabs.=	'>';
		$tabs.=	JText::_( 'Regional TAX Setting' ).'</a></li>';		
		
		$tabs.=	'				</ul>
							<div class="clr"></div>
						</div>
					</div>
					<div class="clr"></div>';
		return $tabs;
  	}
	
  	function getFeedTabs(){
  		global $option;
  		$type = JRequest::getVar('tab','');
  		$tabs = '<div class="submenu-box">
						<div class="submenu-pad">
							<ul id="submenu" class="configuration">';
  		$tabs.= '<li><a href="index.php?option='.$option.'&view=jafeeds&tab=feedlist"';
		if ($type == 'feedlist') {
			$tabs .= ' class="active" ';
		}
		$tabs.=	'>';
		$tabs.=	JText::_( 'Sample feeds' ).'</a></li>';
  		
		$tabs.= '<li><a href="index.php?option='.$option.'&view=jafeeds&tab=userlist"';
		if ($type == 'userlist') {
			$tabs .= ' class="active" ';
		}
		$tabs.=	'>';
		$tabs.=	JText::_( 'User created feeds' ).'</a></li>';
		
  		$tabs.= '<li><a href="index.php?option='.$option.'&view=jaconfiguration&tab=feeds"';
		if ($type == 'feeds') {
			$tabs .= ' class="active" ';
		}
		$tabs.=	'>';
		$tabs.=	JText::_( 'Default Settings' ).'</a></li>';
			
		
		
		$tabs.=	'				</ul>
							<div class="clr"></div>
						</div>
					</div>
					<div class="clr"></div>';
		return $tabs;
  	}
  	
  	function getTabs() {
  		global $option;
  		
		$type = JRequest::getVar('tab','');
		$tabs = '<div class="submenu-box">
						<div class="submenu-pad">
							<ul id="submenu" class="configuration">
								<li><a href="index.php?option='.$option.'&view=jaconfiguration&tab=general"';
		if ($type == 'general' || $type == '') {
			$tabs .= ' class="active" ';
		}		
		$tabs.= '>';
		$tabs .= JText::_( 'General' ).'</a></li>';
		
		$tabs .= '<li><a href="index.php?option='.$option.'&view=jaconfiguration&tab=account"';
		if ($type == 'account') {
			$tabs .= ' class="active" ';
		}
		$tabs.= '>';
		$tabs .= JText::_( 'Accounts & Permissions' ).'</a></li>';	

		$tabs .= '<li><a href="index.php?option='.$option.'&view=jaconfiguration&tab=billing "';
		if ($type == 'billing') {
			$tabs .= ' class="active" ';
		}
		$tabs.= '>';
		$tabs .= JText::_( 'Billing System' ).'</a></li>';		
		
		$tabs .= '<li><a href="index.php?option='.$option.'&view=jaconfiguration&tab=posts "';
		if ($type == 'posts') {
			$tabs .= ' class="active" ';
		}
		$tabs.= '>';
		$tabs .= JText::_( 'Job Posting' ).'</a></li>';	
		
		$tabs.= '<li><a href="index.php?option='.$option.'&view=jaconfiguration&tab=payment"';
		if ($type == 'payment') {
			$tabs .= ' class="active" ';
		}
		$tabs.=	'>';
		$tabs.=	JText::_( 'Payment' ).'</a></li>';
		
		$tabs.= '<li><a href="index.php?option='.$option.'&view=jaconfiguration&tab=currency"';
		if ($type == 'currency') {
			$tabs .= ' class="active" ';
		}
		$tabs.=	'>';
		$tabs.=	JText::_( 'Currency' ).'</a></li>';
		
		
		
		$tabs.= '<li><a href="index.php?option='.$option.'&view=jaconfiguration&tab=emails"';
		if ($type == 'emails') {
			$tabs .= ' class="active" ';
		}
		$tabs.=	'>';
		$tabs.=	JText::_( 'Email Settings' ).'</a></li>';
		
		$tabs.= '<li><a href="index.php?option='.$option.'&view=jaconfiguration&tab=seo"';
		if ($type == 'seo') {
			$tabs .= ' class="active" ';
		}
		$tabs.=	'>';
		$tabs.=	JText::_( 'Meta  Data' ).'</a></li>';
		
		$tabs.= '<li><a href="index.php?option='.$option.'&view=jaconfiguration&tab=cache"';
		if ($type == 'cache') {
			$tabs .= ' class="active" ';
		}
		$tabs.=	'>';
		$tabs.=	JText::_( 'Cache' ).'</a></li>';

//		$tabs.= '<li><a href="index.php?option='.$option.'&view=jaconfiguration&tab=feeds"';
//		if ($type == 'feeds') {
//			$tabs .= ' class="active" ';
//		}
//		$tabs.=	'>';
//		$tabs.=	JText::_( 'Feeds' ).'</a></li>';
			
		
		
		$tabs.=	'				</ul>
							<div class="clr"></div>
						</div>
					</div>
					<div class="clr"></div>';
		return $tabs;
	}
}
?>